'use strict';
/////////////////////////////////////
// 城市选择器
// =====================
// liuyp 2019年2月22日09:50:55
/////////////////////////////////////
function cityPicker($timeout) {
    return {
        restrict: 'AE',
        scope: { cityPicker: '=' },
        link: function (scope, el, attrs) {
            var $element = $(el)
            var address = null;
            scope.$watch("cityPicker", function(n,o){
                if( address == n ) { return }
                if( !n ){ init('','','') }
                else{
                    var t1 = parseInt(n),
                        t2 = t1 - (t1%100),
                        t3 = t1 - (t1%10000),
                        x1 = window.ChineseDistricts["88"][String(t3)],
                        x2 = window.ChineseDistricts[String(t3)][String(t2)],
                        x3 = window.ChineseDistricts[String(t2)][String(t1)];
                    init(x1, x2, x3);
                }
            });
            function init(x1, x2, x3){
                $element.citypicker('destroy');
                $element.citypicker({
                    province: x1, city: x2, district: x3,
                    callback: function(v){
                        address = v.replace(/.*\//g, '');
                        $timeout(function(){ scope.cityPicker = address });
                    }
                });
            }
        }
    }
}
exports = module.exports = cityPicker;